import axios from 'axios'

// 创建axios实例
const request = axios.create({
  baseURL: 'http://localhost:9090/api',  // 直接使用后端地址
  timeout: 10000,
  headers: {
    'Content-Type': 'application/json;charset=utf-8'
  },
  withCredentials: true  // 允许跨域请求携带凭证
})


// 响应拦截器
request.interceptors.response.use(
  response => {
    return response.data
  },
  error => {
    console.error('响应错误:', error.message || '未知错误')
    return Promise.reject(error)
  }
)

// 文件上传配置
export const uploadConfig = {
  baseURL: 'http://localhost:9090/api',
  headers: {
    'Content-Type': 'multipart/form-data'
  },
  withCredentials: true
}

export default request
